import { ChristmasActivitiesInfo } from "../../../model/ChristmasActivitiesInfo";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { FlyFootBmp } from "../../mapUI/flyFoot/FlyFootBmp";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { AIManager } from "../../../scene/ai/AIManager";
import { AIType } from "../../../scene/ai/AIType";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
//class ChristmasItem
    
    export  class ChristmasItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        public get info(): ChristmasActivitiesInfo
        {
            return this._info;
        }

        /* internal  */initUI(): void
        {
            this._itemBg = ResouceConst.getScaleBitmap(ImagesConst.PackItemBg);
            this._itemBg.width = 66;
            this._itemBg.height = 66;
            this._itemBg.x = 5;
            this._itemBg.y = 6;
            addChild(this._itemBg);
            this._itemBmp = new Object /* flash.display.Bitmap */();
            this._itemBmp.x = this._itemBg.x + 3;
            this._itemBmp.y = this._itemBg.y + 3;
            addChild(this._itemBmp);
            this._nameTxt = new Object /* flash.text.TextField */();
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nameTxt.mouseEnabled = false;
            this._nameTxt.wordWrap = true;
            this._nameTxt.multiline = true;
            this._nameTxt.textColor = 16776960;
            this._nameTxt.filters = [FilterConst.nameGlowFilter];
            this._nameTxt.width = 100;
            this._nameTxt.height = 40;
            this._nameTxt.x = this._itemBg.x + this._itemBg.width + 10;
            this._nameTxt.y = this._itemBg.y + 5;
            addChild(this._nameTxt);
            this._optTxt = new Object /* flash.text.TextField */();
            this._optTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._optTxt.filters = [FilterConst.nameGlowFilter];
            this._optTxt.width = 80;
            this._optTxt.height = 20;
            this._optTxt.addEventListener(flash.events.TextEvent.LINK, this.onOptTextLinkHandler);
            this._optTxt.x = this._nameTxt.x;
            this._optTxt.y = this._itemBg.y + 38;
            this._optTxt.htmlText = "<u><a href=\'event: 0\'>" + HTMLUtil.addColor(Language.getString(20410), "#00ff00") + "</u></a>";
            addChild(this._optTxt);
            this._flyFoot = new FlyFootBmp();
            this._flyFoot.x = this._optTxt.x + this._optTxt.textWidth + 2;
            this._flyFoot.y = this._optTxt.y;
            this._flyFoot.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyFootClickHandler);
            addChild(this._flyFoot);
            this._overSkin = ResouceConst.getScaleBitmap(ImagesConst.Friend_over);
            this._overSkin.width = this.width;
            this._overSkin.height = this.height;
            this._downSkin = GlobalClass.getBitmap(ImagesConst.SelectedBg);
            this._downSkin.width = this.width;
            this._downSkin.height = this.height;
            addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            return;
        }

        /* internal  */onOptTextLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._info) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChristmasOptReq, this._info));
            }
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info && this._info.targetInfo) 
            {
                AIManager.onAIControl(this._info.targetInfo, AIType.AI_Convey);
            }
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._seletcted) 
            {
                addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
                if (!contains(this._overSkin)) 
                {
                    addChildAt(this._overSkin, 0);
                }
            }
            return;
        }

        /* internal  */onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            removeEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            if (contains(this._overSkin)) 
            {
                removeChild(this._overSkin);
            }
            return;
        }

        /* internal  */onItemImgLoaded(arg1: ImageInfo): void
        {
            if (arg1 && arg1.bitmapData) 
            {
                this._itemBmp.bitmapData = arg1.bitmapData;
            }
            return;
        }

        public updateData(arg1: ChristmasActivitiesInfo): void
        {
            if (this._info == null) 
            {
                this._info = arg1;
                this._nameTxt.htmlText = HTMLUtil.addColor(this._info.name, "#ffff00");
                LoaderManager.instance.load(this._info.imgSrc, this.onItemImgLoaded);
                if (this._info.optDes == null || this._info.optDes == "") 
                {
                    if (contains(this._optTxt)) 
                    {
                        removeChild(this._optTxt);
                    }
                }
                else 
                {
                    this._optTxt.htmlText = "<u><a href=\'event: 0\'>" + HTMLUtil.addColor(this._info.optDes, "#00ff00") + "</u></a>";
                    if (!contains(this._optTxt)) 
                    {
                        addChild(this._optTxt);
                    }
                }
                if (this._info.showFly) 
                {
                    if (!contains(this._flyFoot)) 
                    {
                        addChild(this._flyFoot);
                    }
                }
                else if (contains(this._flyFoot)) 
                {
                    removeChild(this._flyFoot);
                }
            }
            this.refreshData();
            return;
        }

        /* internal  */refreshData(): void
        {
            return;
        }

        public selected(arg1: Boolean): void
        {
            this._seletcted = arg1;
            if (this._seletcted) 
            {
                if (contains(this._overSkin)) 
                {
                    removeChild(this._overSkin);
                }
                if (!contains(this._downSkin)) 
                {
                    addChildAt(this._downSkin, 0);
                }
            }
            else if (contains(this._downSkin)) 
            {
                removeChild(this._downSkin);
            }
            return;
        }

        public dispose(): void
        {
            this._info = null;
            return;
        }

        public /* override */ get height(): number
        {
            return 80;
        }

        public /* override */ get width(): number
        {
            return 166;
        }

        /* internal */ /* var */_info: ChristmasActivitiesInfo;

        /* internal */ /* var */_selectedBg: ScaleBitmap;

        /* internal */ /* var */_itemBg: ScaleBitmap;

        /* internal */ /* var */_itemBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_optTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_flyFoot: FlyFootBmp;

        /* internal */ /* var */_overSkin: ScaleBitmap;

        /* internal */ /* var */_downSkin: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_seletcted: Boolean;
    }
